#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFiGeneric.h>

/** Global Macro **/
#define ENABLE_SWITCH_BUTTON



/** Hardware pin define **/
#define PWM_PIN 5
#define BUTTON_PIN 0


#define PWM_FREQUENCY 100.0f
#define PWM_FRACTION 10000
#define SERVO_MAX_ANGLE 300

//0.5ms - 2.5ms
#define PWM_SETP_DEG (0.002f * PWM_FREQUENCY * PWM_FRACTION / SERVO_MAX_ANGLE )
#define PWM_BASE     (PWM_FRACTION * (PWM_FREQUENCY / 2000))

#ifdef ENABLE_SWITCH_BUTTON
#endif

void servo_set_angle(int deg)
{
  analogWrite(PWM_PIN, PWM_BASE + PWM_SETP_DEG * deg);
}

void setup()
{
  pinMode(PWM_PIN,OUTPUT);
  analogWriteFreq(PWM_FREQUENCY);
  analogWriteRange(PWM_FRACTION);
  servo_set_angle(0);
  Serial.begin(9600);
  // Serial.println("esp8266 test");
#ifdef ENABLE_SWITCH_BUTTON
  pinMode(BUTTON_PIN,INPUT_PULLUP);
  // PIN_PULLUP_EN(BUTTON_PIN);
#endif
}
//主循环
void loop()
{
  
#ifdef ENABLE_SWITCH_BUTTON
  if(digitalRead(BUTTON_PIN) == LOW)
  {
    printf("Detected Pressed\n");
    delay(10);
    if(digitalRead(BUTTON_PIN) == LOW)
    {
      for(int i = 0; i < 2 ; i++)
      {
#endif
        servo_set_angle(0);
        delay(2000);
        servo_set_angle(90);
        delay(2000);
#ifdef ENABLE_SWITCH_BUTTON
      }
    }
  }
#endif
}